﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SpeakOut.Lib
{
    public static class LinqExtensionMethods
    {
        public static bool HasElement<T>(this IEnumerable<T> col, Func<T,bool> func)
        {
            return col.Count(func) > 0;
        }

        public static string ConcatenateStrings<T>(this IEnumerable<T> enumerable, Func<T,string> func, string separator)
        {
            if (enumerable == null || enumerable.Count() == 0) return string.Empty;

            StringBuilder sb = new StringBuilder();
            foreach (var element in enumerable.Select(func))
            {
                sb.AppendFormat("{0}{1}",separator, element);
            }
            return  sb.Remove(0,separator.Length).ToString();
        }
    }
}
